package view.table;

import java.awt.Color;
import java.awt.Component;
import java.awt.Font;

import javax.swing.JTable;
import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableCellRenderer;

@SuppressWarnings("serial")
public class GenericTableRenderer extends DefaultTableCellRenderer {
	
	private static final Font FONT = new Font("Arial", Font.PLAIN, 14);
	
	private static final Color COLOR_BCK_EVEN_ROW = Color.GRAY;
	private static final Color COLOR_LBL_EVEN_ROW = Color.WHITE;
	private static final Color COLOR_BCK_ODD_ROW = Color.WHITE;
	private static final Color COLOR_LBL_ODD_ROW = Color.BLACK;
	
	private static final int COLUMN_INDEX_ATT = 0;
	private static final int COLUMN_INDEX_VALUE = 1;
	
	@Override
	public Component getTableCellRendererComponent(JTable table, Object value, boolean selected, boolean focused, int row, int column) {
		setHorizontalAlignment(SwingConstants.CENTER);
		setVerticalAlignment(SwingConstants.CENTER);
		setFont(FONT);
		
		if (row % 2 == 0) {
			setBackground(COLOR_BCK_EVEN_ROW);
			setForeground(COLOR_LBL_EVEN_ROW);
		} else {
			setBackground(COLOR_BCK_ODD_ROW);
			setForeground(COLOR_LBL_ODD_ROW);
		}
		
		if (column == COLUMN_INDEX_VALUE) {
			setToolTipText(value.toString());
		}
		return super.getTableCellRendererComponent(table, value, selected, focused, row, column);
	}
}
